package com.example.module_clocking.adapter

import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.example.module_clocking.R
import com.example.module_clocking.databinding.ItemClockTypeBinding
import com.example.module_clocking.model.ClockTypeEntity


class ClockingTypeAdapter :RecyclerView.Adapter<ClockingTypeAdapter.ClockingViewHolder>(){
    private val list  = mutableListOf<ClockTypeEntity>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClockingViewHolder {
        val binding=ItemClockTypeBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ClockingViewHolder(binding)
    }
    fun setData(list:MutableList<ClockTypeEntity>){
        this.list.clear()
        this.list.addAll(list)
        notifyDataSetChanged()
    }
    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: ClockingViewHolder, position: Int) {
        val binding=DataBindingUtil.getBinding<ItemClockTypeBinding>(holder.itemView)?:return
        binding.tvClockType.text=list[position].type
        binding.tvClockType.setOnClickListener {
            if (list[position].type=="全部"){
                binding.tvClockType.setTextColor(Color.WHITE)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }else{
                binding.tvClockType.setTextColor(Color.BLACK)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }
            if (list[position].type=="正常"){
                binding.tvClockType.setTextColor(Color.WHITE)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }else{
                binding.tvClockType.setTextColor(Color.BLACK)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }
            if (list[position].type=="迟到"){
                binding.tvClockType.setTextColor(Color.WHITE)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }else{
                binding.tvClockType.setTextColor(Color.BLACK)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }
            if (list[position].type=="早退"){
                binding.tvClockType.setTextColor(Color.WHITE)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }else{
                binding.tvClockType.setTextColor(Color.BLACK)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }
            if (list[position].type=="缺勤"){
                binding.tvClockType.setTextColor(Color.WHITE)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }else{
                binding.tvClockType.setTextColor(Color.BLACK)
                binding.tvClockType.setBackgroundResource(R.drawable.shape_type_clock04)
            }

        }

    }

    class ClockingViewHolder(item:ItemClockTypeBinding) : RecyclerView.ViewHolder(item.root)
}